package cn.jsj.invite.configuration;

import cn.jsj.invite.interceptor.SecurityInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author 卢斌
 */
@Configuration
public class ConnectorConfiguration implements WebMvcConfigurer {

    private final SecurityInterceptor interceptor;

    @Autowired
    public ConnectorConfiguration(SecurityInterceptor interceptor) {
        this.interceptor = interceptor;
    }

    /**
     * 配置一个拦截器，这里会拦截所有请求
     *
     * @param interceptorRegistry 配置拦截器
     */
    @Override
    public void addInterceptors(InterceptorRegistry interceptorRegistry) {
        String[] addpath = {"/**"};
        String[] staticResourcePath = {"/css/**","/favicon.ico", "/img/**", "/js/**", "/index.html"};
        interceptorRegistry.addInterceptor(interceptor)
                .addPathPatterns(addpath)
                .excludePathPatterns(staticResourcePath);
    }

}
